<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/12/01/0001
 * Time: 11:51
 */

namespace app\sports_admin\model;

use think\Model;
class Region extends Model
{
    protected $table = 'table_region';

    protected $pk = 'id';

    protected $hidden = ['add_time','update_time'];

    /**
     * 根据城市名称获取城市id
     * @param $city城市名称
    */
    public static function getCityId($city)
    {
        return self::where('region_name',$city)->value('id');
    }
    /**
     * 根据城市id获取城市名称
     * @param $regionId 城市id
    */
    public static function getCityName($regionId)
    {
        return self::where('id',$regionId)->value('region_name');
    }
    public static function getCity()
    {
        return self::where('parent_id',1)->select();
    }
    /**
     * 获取城市名
     */
    public static function addGatherPage()
    {
        return self::field('id,region_name')->whereIn("parent_id",[1,0])->select();
    }
    /*
     * 查询开通的地区
     * @param $id 城市id
     */
    public function isPassRegion($id)
    {
        $data = self::where('is_pass',1)->where('parent_id',1)->where('region_type',1)
            ->where(function($query)use($id){
                if($id){
                    $query->where('id',$id);
                }
            })->field('id,parent_id,region_name,region_type,is_pass')->paginate(1);
        return $data;
    }
    /*
     * 获取开通的省
     */
    public static function province()
    {
        return self::where('is_pass',1)->where('parent_id',1)->field('id,region_name')->select();
    }
    /*
     * 查询市级信息
     */
    public static function cityInfo($id)
    {
        return self::where('parent_id',$id)->field('id,region_name,parent_id')->select();
    }
}